<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 验证栈序列 -->
    <script>
      var validateStackSequences = function (pushed, popped) {
        const stack = []
        let j = 0
        for (let i = 0; i < pushed.length; i++) {
          stack.push(pushed[i])
          while (stack.length != 0 && popped[j] === stack[stack.length - 1]) {
            j++
            stack.pop()
          }
        }
        return stack.length === 0
      }
      // console.log(validateStackSequences([1, 2, 3, 4, 5], [4, 5, 3, 2, 1]))
      console.log(validateStackSequences([1, 2, 3, 4, 5], [4, 3, 5, 1, 2]))
    </script>
  </body>
</html>
